YUI().use('node','dd-drop', 'dd-ddm-drop','dd-constrain','io', function(Y) {
      //Static Vars
        var goingUp = false, lastY = 0;
		var ok = false;
		var drags = Y.Node.all('#category_first  div.item-entry');
        drags.each(function(v, k) {
            
    var dd = new Y.DD.Drag({
                node: v,
                dragMode: 'intersect'
            }).plug(Y.Plugin.DDConstrained, {
                constrain2node: '#category_first'
            });
			
            dd.on('drag:drag', function(e) {
                //Get the last y point
                var y = e.target.lastXY[1];
                //is it greater than the lastY var?
                if (y < lastY) {
                    //We are going up
                    goingUp = true;
                } else {
                    //We are going down.
                    goingUp = false;
                }
                //Cache for next check
                lastY = y;
            });	
            
            dd.on('drag:start', function() {
                ok=false;
              //e.setStyle('opacity', '.25');
              
                //  e.setStyle('z-index', '11');
                 var p = this.get('dragNode'),
                    n = this.get('node');
                    n.setStyle('opacity', .95);
                    n.setStyle('z-index', 11);
            });
            dd.on('drag:end', function(e) {
                  var p = this.get('dragNode'),
                    n = this.get('node');
                    n.setStyle('opacity', 1);
                    n.setStyle('z-index', 10);
              //  e.setStyle('z-index', '10');
                // e.setStyle('opacity', '1');
				 
                                 if(ok){
					//alert('removed ');
				  }else{
					e.preventDefault();
					//alert('dont remove ');
				  } 
                                 
                //e.preventDefault();
				
            });
			 
                         
                          dd.on('drag:drophit', function(e) {
                               var p = this.get('dragNode'),
                                 n = this.get('node');
                              //var  in = n.get('intput');
                              var itemIdRemove = p.one('input[name=itemId][type=hidden]').get('value');
                              
                              var answer = confirm("You want to remove ? ");
                                if (answer){
                                    // ajax call 
                                        ok = true;
                                     
                                        Y.io('index.php/item/deleteItem/'+itemIdRemove,
                                            {
                                                on: {success: function(){
                                                        //alert('success');
                                                }}
                                            });
                                        
					e.target.get('node').remove();
                                        return true;
                                }
                                else{
                                    ok = false;
                                    return false;
                                }
				  
            });
        });

		
		// drop 
                
        
        var drop_entry = new Y.DD.Drop({
            node: 'div.drop-remove-container_first'
        });
        drop_entry.on('drop:hit', function(e) {
		//alert('drop:hit');
           /* 
             var drag = e.drag;
            var out = ['id: ' + drag.get('node').get('id')];
            var str = '<p><strong>Dropped</strong>: ' + out.join(', ') + '</p>';
            this.get('node').set('innerHTML', str);
             */
        });
});


function confirmation() {
	var answer = confirm("You want to remove");
	if (answer){
            // ajax call 
                return true;
	}
	else{
		alert("Thanks for sticking around!");
        return false;
	}
}

    
    
    function prev_ItemEntries($_category_id){
        var   index_value = jQuery("#list-one input[name=item_index]").val();
        //alert('index_value '+ index_value);
        
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/prev_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery("div.item-entry-container-first").html(respone);
                }
            });
    }
    
    function next_ItemEntries ($_category_id){
        var   index_value = jQuery("#list-one input[name=item_index]").val();
        //alert('index_value '+ index_value);
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/next_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery("div.item-entry-container-first").html(respone);
                }
            });
    }


    function prev_ItemEntries2($_category_id, varDiv){
       // var   index_value = jQuery("#list-one input[name=item_index]").val();
       
var select =  varDiv+' input[name=item_index]';
        var   index_value = jQuery(select ).val();
 //alert("index_value "+index_value );
        
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/prev_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery(varDiv).html(respone);
                }
            });
    }
    
    function next_ItemEntries2 ($_category_id, varDiv){

	var select =  varDiv+' input[name=item_index]';
        var   index_value = jQuery(select ).val();
        //alert(varDiv);
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/next_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery(varDiv).html(respone);
                }
            });
    }

 
